<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="支付单号">
                    <el-input
                            class="w-[150px]"
                            v-model="queryParams.payment_trade"
                            placeholder="请输入支付单号"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="充值类型">
                    <el-select class="w-[280px]" v-model="queryParams.type" clearable>
                        <template v-for="item in optionsData">
                            <el-option :value="item.type" :label="item.name">{{item.name}}</el-option>
                        </template>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
                <el-form-item style="float: right">
                    <div>
                        <el-button type="success" @click="addLog">充值余额</el-button>
                    </div>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists" style="width: 100%" @selection-change="handleSelectionChange">
<!--                <el-table-column type="selection" width="55" />-->
                <el-table-column label="订单号" prop="order_no" min-width="200" />
                    
				
                <el-table-column sortable label="充值金额" prop="payment_amount" min-width="120" />
                   
				<el-table-column  label="去充值" prop="url" min-width="200" >
					<template #default="{ row }">
						<div v-if="row.is_pay==1" v-html="row.html" style="background: #4a5dff;color: #fff;padding: 5px 0px;width: 100px;text-align: center;border-radius: 5px;"></div>
						<div v-if="row.payment_status==0&&row.is_pay==2">已失效</div>
						<div v-if="row.payment_status==1&&row.is_pay==2">已完成</div>
					</template>
				</el-table-column>
               
                <el-table-column label="创建时间" prop="name" min-width="180">
                    <template #default="{ row }">
                        {{ row.created_at }}
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
    <CutPop v-if="showCutPop" @success="getLists" ref="addRef"></CutPop>
</template>
<script lang="ts" setup>
    import { ZfbRechargeLog, ZfbRecharge } from '@/api/finance'
    import { usePaging } from '@/hooks/usePaging'
    import CutPop from "./component/CutPop.vue";

    const queryParams = reactive({
        payment_trade: '',
        type: '',
    });

    const { pager, getLists, resetPage, resetParams } = usePaging({
        fetchFun: ZfbRechargeLog,
        params: queryParams
    });

    getLists();

    const optionsData = [
        {
            type: 1,
            name: '红包充值'
        },
        {
            type: 2,
            name: '流量充值'
        }
    ];

    // 充值余额
    const addRef = shallowRef<InstanceType<typeof CutPop>>();
    let showCutPop = ref(false);
    const addLog = async (id: string) => {
        showCutPop.value = true;
        await nextTick();
        addRef.value?.open();
    };

    const handleSelectionChange = (val: any) => {
        console.log(val)
    }

</script>
